<%@ page language="java" pageEncoding="UTF-8" %>
<script type="text/javascript">
	$(function(){
		
		 $('#wdxx_maps_dept').combotree({
				line:true,
				url:'deptAction!do_combotree.action',
				panelHeight:260,
				required:true,
				editable:false,
				idField:'id',
				textField:'text',
				parentField:'pid',
				 onBeforeSelect: function(node) {
			            if ($(this).tree('getParent', node.target)==null) {
			                return false;
			            }
			        },
			        onClick: function(node) {
			            if ($(this).tree('getParent', node.target)==null) {
			                $('#wdxx_maps_dept').combo('showPanel');
			            }
			        }
			}); 
		
		
	});
	
	function _showWdxxMaps(){
		
		$.ajax({
			url : '${pageContext.request.contextPath}/wdxxAction!getWdxxs.action',
			data : {
				deptId : $('#wdxx_maps_dept').combotree('getValue')
			},
			dataType : 'json',
			success : function(d) {
				if (d.length >0){
					var map = new BMap.Map('show_wd_map'); // 创建Map实例
					var point = new BMap.Point(d[0].cjd, d[0].cwd);//创建点坐标
					map.centerAndZoom(point, 11); // 初始化地图,设置中心点坐标和地图级别
					map.setCurrentCity(d[0].cds); 
					map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
					map.addControl(new BMap.NavigationControl());//添加地图平移缩放控件
					var pointArr = new Array(); //存放标注点经纬信息的数组
                    var markerArr = new Array(); //存放标注点对象的数组
                    var contentArr = new Array(); //存放提示信息窗口对象的数组
                    var searchInfoWindowArr =new Array();//存放检索信息窗口对象的数组
					for (var i=0;i<d.length;i++){
						pointArr[i] = new BMap.Point(d[i].cjd,d[i].cwd);
						markerArr[i] = new BMap.Marker(pointArr[i]);
						map.addOverlay(markerArr[i]);
	                    //markerArr[i].setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
	                    //var label = new window.BMap.Label(d[i].cname, { offset: new window.BMap.Size(20, -10) });
	                    //markerArr[i].setLabel(label);
						var wdtype='';
						switch(d[i].ctype){
						case 1: wdtype="储蓄网点";break;
						case 2: wdtype="营业网点";break;
						}
						contentArr[i] = '<div style="margin:0;line-height:20px;padding:2px;">' + '地址:'+d[i].caddress+'<br/>电话:'+d[i].cphone+'<br/>网点类型:'+wdtype + '&nbsp;&nbsp;&nbsp;台席数:'+d[i].ctx+'<br />员工总数:'+d[i].czrs+'人&nbsp;&nbsp;&nbsp;ATM:'+d[i].catm+'台<br /></div>';
						//创建检索信息窗口对象
						searchInfoWindowArr[i] =  new BMapLib.SearchInfoWindow(map, contentArr[i], {
							title : d[i].cname, //标题
							width : 130, //宽度
							height : 80, //高度
							enableMessage:false,
							panel : "panel", //检索结果面板
							enableAutoPan : true, //自动平移
							searchTypes : [ BMAPLIB_TAB_SEARCH //周边检索
							//BMAPLIB_TAB_TO_HERE,  到这里去
							//BMAPLIB_TAB_FROM_HERE 从这里出发
							]
						});
						 markerArr[i].addEventListener("click", 
		                            (function(k){
		                                // js 闭包
		                                return function(){
		                                    //将被点击marker置为中心
		                                    //map.centerAndZoom(point[k], 18);
		                                    //在marker上打开检索信息窗口
		                                    searchInfoWindowArr[k].open(markerArr[k]);
		                                };
		                            })(i)                            
		                        ); 
					}
				}
			}
		});
	}

</script>

<div class="easyui-layout" data-options="fit:true" style="overflow: hidden;">
	<div data-options="region:'north',title:'查询网点',iconCls:'icon-search'" style="height: 80px;padding:5px;overflow: hidden;">
		<div style="padding:5px">
			<form method="post" id="wdxx_maps_search_form" style="display:inline">
			<span>所属机构：</span>
			<input id="wdxx_maps_dept"  name="deptId"  style="width:180px"/>&nbsp;&nbsp;
			</form>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-marker'" onclick="_showWdxxMaps();">查看地图</a>&nbsp;
		</div>
	</div>
	<div data-options="region:'center',title:'网点地图',border:true,iconCls:'icon-hamburg-product-design'" style="overflow: hidden;height:400px">
		<div id="show_wd_map" class="baiduMap" ></div>
	</div>
</div>

